package ppt

import (
	"context"

	v1 "web-ppt/api/ppt/v1"

	"github.com/gogf/gf/v2/frame/g"
)

func (c *ControllerV1) ContentList(ctx context.Context, req *v1.ContentListReq) (res *v1.ContentListRes, err error) {
	clist, count, err := c.ppt.ContentList(ctx, req.Tid, req.Page, req.Size)
	if err != nil {
		return nil, err
	}

	tlist, err := c.ppt.AllList(ctx)
	if err != nil {
		return nil, err
	}

	pptname := ""
	for _, v := range tlist {
		if v["id"].Int() == req.Tid {
			pptname = v["name"].String()
		}
	}

	page := c.view.Page(ctx, count, req.Size)

	c.view.RenderTpl(ctx, "ppt/content.html", g.Map{
		"contentlist": clist,
		"page":        page,
		"pptname":     pptname,
		"tagslist":    tlist,
		"pptid":       req.Tid,
	})
	return nil, err
}
